﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Company.Hardware;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using 无人值守地磅称重系统.Interfaces;
using 无人值守地磅称重系统.Models.Menu;
using 无人值守地磅称重系统.Models.Message;

namespace 无人值守地磅称重系统.ViewModels
{
    public class MainViewModel : ObservableObject
    {
        public List<MenuEntity> MenuEntities { get; }

        public ICommand NavigationCommand { get;  }

        public ICommand LogoutCommand { get; }

        public ISession Session { get; }

        public IScale Scale { get; }

        public ICamera Camera { get; }

        public ICameraIce CameraIce { get; }



        public MainViewModel(ISession session, IScale scale,ICamera camera, ICameraIce cameraIce)
        {
            Session = session;
            Scale = scale;
            Camera = camera;

            MenuEntities = new List<MenuEntity>();
            MenuEntities.Add(new MenuEntity("首页", "Home", "IndexView"));
            MenuEntities.Add(new MenuEntity("报表", "ChartBar", "ReportView"));
            MenuEntities.Add(new MenuEntity("车辆", "DumpTruck", "CarView"));
            MenuEntities.Add(new MenuEntity("物资", "Shop", "StuffView"));
            MenuEntities.Add(new MenuEntity("公司", "Charity", "CompanyView"));
            MenuEntities.Add(new MenuEntity("用户", "User", "UserView"));
            MenuEntities.Add(new MenuEntity("设置", "SettingsApplications", "ConfigView"));
            MenuEntities.Add(new MenuEntity("测试", "SettingsApplications", "TestView"));

            NavigationCommand = new RelayCommand<MenuEntity>(Navigation);

            LogoutCommand = new RelayCommand(Logout);
            Camera = camera;
            CameraIce = cameraIce;
        }

        private void Logout()
        {
            WeakReferenceMessenger.Default.Send(new LogoutMessage(Session.CurrentUser));
        }

        private void Navigation(MenuEntity item)
        {
            WeakReferenceMessenger.Default.Send(item);
        }
    }
}
